package com.example.demo.test;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import java.util.HashMap;
import java.util.Map;
@Slf4j
public  class test {
    /**
     * 定时任务执行方法
     * @param autoUpdate2
     * @return
     * @throws Exception
     */
    public static HashMap  timeTask(AutoUpdateRequestInfo autoUpdate2) throws Exception {
        //A 取出对应配置信息 次数和时间进行操作
        //响应转化成对象
        AutoUpdateResponseInfo responseInfo = new AutoUpdateResponseInfo();
        AutoUpdateRequestInfo autoUpdate = new AutoUpdateRequestInfo();
        //对象封装成Map
        Map<String, Object> request = BeanUtil.beanToMap(autoUpdate);
        try {
            //发起请求 https://192.168.0.2:8089/getlogin
            String response = HttpUtil.post("https://"+"第三方地址", request,10000);
            //响应转化成对象
            responseInfo = JSONUtil.toBean(response, AutoUpdateResponseInfo.class);
        }catch (Exception e){
            e.printStackTrace();
            throw new Exception("登录时 服务器地址错误");
        }
        if (!responseInfo.getAutoCode().equals("0")){
            throw new Exception(responseInfo.getMsg());}
        //对象封装成Map
        Map<String, Object> request2 = BeanUtil.beanToMap(autoUpdate2);
        //响应转化成对象
        AutoUpdateResponseInfo responseInfo2 = new AutoUpdateResponseInfo();
        try {
            //发起请求 "https://"+logServer.getIp()+ ":8089/getlogin", 网络延迟导致查询不出来、设置了10分钟时长限制
            String response3 = HttpRequest.post("https://"+ ":8089/data/Gamelog/page").header("x-wlk-Authorization", responseInfo.getData()).form(request2).timeout(600000).execute().body();
            //响应转化成对象
            responseInfo2 = JSONUtil.toBean(response3, AutoUpdateResponseInfo.class);
        }catch (Exception e){
            e.printStackTrace();
            throw new Exception("查询时 服务器地址错误");
        }
        if (!responseInfo2.getAutoCode().equals("0")){
            throw new Exception(responseInfo2.getMsg());
        }
        HashMap hashMap = new HashMap();
        return hashMap;
    }
}
